package com.jz.community.moduleshoppingguide.nearshop.ui.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.moduleshoppingguide.R;
import com.jz.community.moduleshoppingguide.nearshop.bean.CategoriesBean;

import java.util.List;


/**
 * Created by Ani_H on 2018/3/6.
 */

public class NearShopTypeAdapter extends BaseQuickAdapter<CategoriesBean.EmbeddedBeanXX.ContentBean, BaseViewHolder> {

    TypeChoose typeChoose;

    public NearShopTypeAdapter(int layoutResId, @Nullable List<CategoriesBean.EmbeddedBeanXX.ContentBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CategoriesBean.EmbeddedBeanXX.ContentBean entity) {
        boolean isSelect = entity.isSelect();
        TextView pop_tv = helper.getView(R.id.item_pop_tv);
        pop_tv.setText(entity.getName());
        if (isSelect) {
            pop_tv.setBackgroundResource(R.drawable.border_loc_red_line);
            pop_tv.setTextColor(mContext.getResources().getColor(R.color.home_red));
        } else {
            pop_tv.setBackgroundResource(R.drawable.border_loc_gray_line);
            pop_tv.setTextColor(mContext.getResources().getColor(R.color.black));
        }
        pop_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int i = 0; i < mData.size(); i++) {
                    mData.get(i).setSelect(false);
                }
                entity.setSelect(true);
                notifyDataSetChanged();
                typeChoose.currentChoose(entity);
            }
        });
    }

    public interface TypeChoose {
        void currentChoose(CategoriesBean.EmbeddedBeanXX.ContentBean entity);
    }

    public void setTypeChoose(TypeChoose typeChoose) {
        this.typeChoose = typeChoose;
    }
}
